package org.micode.common.enums;

import org.micode.common.helper.I18nMsgHelper;
import org.micode.common.utils.StringExtUtils;

public enum OperationModeEnum {

    /** 普通操作 */
    NORMAL("NORMAL", "Normal operation"),

    /** 更新操作 */
    UPDATE("UPDATE", "Update operation"),

    /** 新增操作 */
    INSERT("INSERT", "Insert operation"),

    /** 删除操作 */
    DELETE("DELETE", "Delete operation"),
    ;

    private String code;

    private String name;

    OperationModeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static OperationModeEnum getByCode(String code) {
        if (null == code) {
            return null;
        }
        for (OperationModeEnum status : OperationModeEnum.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return null;
    }

    public String getName() {
        String ret = I18nMsgHelper.get(this.getClass().getSimpleName() + "." + code);
        if (StringExtUtils.isAnyEmpty(ret)) {
            return name;
        } else {
            return ret;
        }
    }

    public String getCode() {
        return code;
    }

}
